# $Id: PKGBUILD 84438 2013-02-19 02:32:24Z svenstaro $
# Maintainer: Sven-Hendrik Haase <sh@lutzhaase.com>
pkgname=ldc
pkgver=20130219
pkgrel=1
pkgdesc="A D Compiler based on the LLVM Compiler Infrastructure including D runtime and libphobos2"
arch=('i686' 'x86_64')
url="http://www.dsource.org/projects/ldc"
license=('BSD')
depends=('llvm' 'libconfig')
makedepends=('git' 'cmake')
backup=('etc/ldc2.conf')
source=()
md5sums=()

_gitroot=git://github.com/ldc-developers/ldc.git
_gitname=ldc
_gitbranch=master

[[ $CARCH == "x86_64" ]] && _multilib="ON"
[[ $CARCH == "i686" ]] && _multilib="OFF"

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [[ -d "$_gitname" ]]; then
    cd "$_gitname" && git pull origin
    msg "The local files are updated."
  else
    git clone --branch "$_gitbranch" "$_gitroot" "$_gitname"
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting build..."

  rm -rf "$srcdir/$_gitname-build"
  git clone --recursive "$srcdir/$_gitname" "$srcdir/$_gitname-build"
  cd "$srcdir/$_gitname-build"

  mkdir build && cd build
  cmake \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DINCLUDE_INSTALL_DIR=/usr/include/d/std-ldc \
      -DMULTILIB=$_multilib \
      ..
  make
}

package() {
  cd "$srcdir/$_gitname-build"

  cd build
  make DESTDIR=$pkgdir install
  cd ..

  mkdir -p $pkgdir/usr/share/bash-completion/
  mv $pkgdir/etc/bash_completion.d $pkgdir/usr/share/bash-completion/completions

  install -Dm644 LICENSE $pkgdir/usr/share/licenses/$pkgname/LICENSE

  # We don't actually want the multilib libs in this package
  rm -rf $pkgdir/usr/lib32
}
